/**
 * 
 */
package com.pmsco.pms.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.ResourceBundle;

import com.pmsco.pms.core.constant.PmsConstant;

/**
 * @author Long Tran
 *
 */
public class BundleUtil {
	private static final String basename = "pmsmessage";
	private static BundleUtil instance = null;
	private ResourceBundle pmsResource = null;
	
	private BundleUtil() {
		pmsResource = ResourceBundle.getBundle(basename, Locale.US);
	}
	
	public static BundleUtil getInstance() {
		if(instance == null)
			instance = new BundleUtil();
		return instance;
	}
	
	public String getKey(String key) {
		return pmsResource.getString(key);
	}
	
	public String getDefaultDate() {
		String ret = "";
		Integer currentYear = Calendar.getInstance().get(Calendar.YEAR);
		String yearRanges = pmsResource.getString("date.yearRanges");
		String endYearStr = yearRanges.substring(yearRanges.lastIndexOf(":") + 1).trim();
		Integer endYear = currentYear + Integer.valueOf(endYearStr);
		Calendar defaultCal = Calendar.getInstance();
		defaultCal.set(Calendar.YEAR, endYear);
		SimpleDateFormat formatter = new SimpleDateFormat(PmsConstant.dateFormat);
		ret = formatter.format(defaultCal.getTime());
		return ret;
	}
}
